﻿Imports System.Data
Imports Global_Visas_Business_Layer
Partial Public Class frmSearchHistory

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub frmSearchHistory_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Me.KeyUp
        If e.Key = Key.Escape Then
            Me.Close()
        End If
    End Sub

    Private Sub frmSearchHistory_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        GeneralTasks.ChangeTheme(Me)
        GeneralTasks.EnumerateandFill(Me.LogicalChildren)
        'Dim dt As DataTable = CommonDataFunctions.GetSearchHistory(GlobalCRM.CurrentConID)
        DataBinding.BindListView(CommonDataFunctions.GetSearchHistory(GlobalCRM.CurrentConID), Me.lvSearchHistory)
    End Sub

    Private Sub lvSearchHistory_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles lvSearchHistory.MouseDoubleClick
        Dim strCriteria As String = String.Empty
        Dim strSearchType As String

        If lvSearchHistory.SelectedItems.Count > 0 Then

            strSearchType = lvSearchHistory.SelectedItem.row.itemarray(2).ToString
            Dim frmSearch As New frmSearch
            ' name search
            Try


                If strSearchType = "Name" Then
                    If Len(lvSearchHistory.SelectedItem.row.itemarray(0).ToString) > 0 Then
                        ' company search
                        frmSearch.radCompanyName.IsChecked = True
                        strCriteria = lvSearchHistory.SelectedItem.row.itemarray(0).ToString.ToString
                    Else
                        ' surname search
                        frmSearch.radClientFName.IsChecked = True
                        strCriteria = lvSearchHistory.SelectedItem.row.itemarray(1).ToString.ToString
                    End If
                End If

                ' ext ref search
                If strSearchType = "Ext Ref" Then
                    frmSearch.radExtRef.IsChecked = True
                    strCriteria = lvSearchHistory.SelectedItem.row.itemarray(1).ToString
                End If

                ' dob search
                If strSearchType = "DOB" Then
                    frmSearch.radDOB.IsChecked = True
                    strCriteria = lvSearchHistory.SelectedItem.row.itemarray(1).ToString
                End If

                ' email search
                If strSearchType = "E-Mail" Then
                    frmSearch.radEmail.IsChecked = True
                    strCriteria = lvSearchHistory.SelectedItem.row.itemarray(1).ToString
                End If

                frmSearch.txtSearchCriteria.Text = strCriteria
                frmSearch.Show()
                Me.Close()
            Catch ex As Exception
                CommonFuncs.ErrorHandler(ex, "frmSearchHistory : lvSearchHistory_MouseDoubleClick")
            End Try
        End If
    End Sub
End Class
